package pub.wkq.user.controller;


import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pub.wkq.api.controller.intercept.JWTCurrentUserInterceptor;
import pub.wkq.bo.ModifyUserBO;
import pub.wkq.common.base.BaseInfoProperties;
import pub.wkq.common.result.JSONResult;
import pub.wkq.common.utils.JWTUtils;
import pub.wkq.common.utils.SMSUtils;
import pub.wkq.common.utils.SerializationUtils;
import pub.wkq.pojo.Stu;
import pub.wkq.pojo.Users;
import pub.wkq.user.service.StuService;
import pub.wkq.user.service.UserService;
import pub.wkq.vo.UsersVO;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * <p>
 * 用户信息
 * </p>
 *
 * @author 王开琦
 * @since 2023-06-05
 */
@Slf4j
@RestController
@RequestMapping("userinfo")
public class UserInfoController extends BaseInfoProperties {
    @Resource
    private UserService userService;
    @Resource
    private JWTUtils jwtUtils;
    /**
     * 修改
     */
    @PostMapping("modify")
    public JSONResult modify(@RequestBody ModifyUserBO modifyUserBO) {
        userService.modify(modifyUserBO);
        //返回最新用户信息
        Users users = userService.getById(modifyUserBO.getUserId());
        //重新生成并且覆盖原来的 token
        String uToken = jwtUtils.createJwtWithPrefix(SerializationUtils.serializeObject(users), TOKEN_USER_PREFIX);
        UsersVO usersVO = new UsersVO();
        BeanUtils.copyProperties(users, usersVO);
        usersVO.setUserToken(uToken);
        return JSONResult.ok(usersVO);
    }


}

